package com.sharp.authorization.dao.common.repository;

import com.sharp.authorization.dao.common.entity.AcPermit;
import com.sharp.authorization.dao.common.mapper.AcPermitDao;
import com.sharp.kernel.constant.db.SqlConstant;
import com.sharp.kernel.mybatis.repository.BaseMysqlRepository;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Title: AcPermitService
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/6/14 17:53
 */
@Service
public class AcPermitService extends BaseMysqlRepository<AcPermit, AcPermitDao> {

    @Resource
    private AcPermitDao acPermitDao;

    public List<AcPermit> getAllPermitByClientType(String clientType) {
        Map<String, Object> propertyMap = new HashMap<>(2);
        propertyMap.put("valid", SqlConstant.VALID);
        propertyMap.put("clientType", clientType);
        Example example = super.getExample(propertyMap);
        example.orderBy("showOrder").asc();
        return super.select(example);
    }


    public AcPermit getPermitById(String id) {
        return super.selectByPrimaryKey(id);
    }

    public List<AcPermit> getPermitListByParentId(String id) {
        Example example = getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("parentPermitId", id);
        return super.select(example);
    }

    public List<AcPermit> getPermitByIdListAndClientType(List<String> permitIdList, String clientType) {
        Example example = getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("clientType", clientType);
        criteria.andIn("id", permitIdList);
        criteria.andEqualTo("valid", SqlConstant.VALID);
        return super.select(example);
    }

}


